package com.jiot.exce;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;


/**
 * 对系统异常时的统一处理
 */
public class GlobalExceptionInterceptor implements Interceptor {

	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		try {
			controller.getResponse().setHeader("server","BeiFengLiangYue");
			inv.invoke();
		} catch (Throwable e) {
			Ret ret = Ret.fail().set("error", e.getMessage());
			controller.renderJson(ret);
			return;
		}

	}
}
